﻿// CAjust1Dlg.cpp: 实现文件
//

#include "pch.h"
#include "CAjust1Dlg.h"
#include "afxdialogex.h"
#include "resource.h"

// CAjust1Dlg 对话框

IMPLEMENT_DYNAMIC(CAjust1Dlg, CDialogEx)

CAjust1Dlg::CAjust1Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_AJUST_1, pParent)
{

}

CAjust1Dlg::~CAjust1Dlg()
{
}

void CAjust1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CAjust1Dlg, CDialogEx)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_NCLBUTTONDOWN()
	ON_WM_NCLBUTTONUP()
	ON_WM_MOVING()
	ON_WM_CLOSE()
	ON_COMMAND(ID_Linear0A, &CAjust1Dlg::OnLinear0a)
	ON_COMMAND(ID_Linear2A, &CAjust1Dlg::OnLinear2a)
	ON_COMMAND(ID_Linear5A, &CAjust1Dlg::OnLinear5a)
	ON_COMMAND(ID_Linear10A, &CAjust1Dlg::OnLinear10a)
	ON_WM_RBUTTONUP()
END_MESSAGE_MAP()


// CAjust1Dlg 消息处理程序


BOOL CAjust1Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	bBD = FALSE;
	m_bBtnDn = FALSE;

	// TODO:  在此添加额外的初始化

	this->MoveWindow(1920 - 600, 0, 600, 600);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CAjust1Dlg::OnClose()
{
	m_pViewController->OnMainDialogClose();

	CDialogEx::OnClose();
}


void CAjust1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	bBD = TRUE;

	CDialogEx::OnLButtonDown(nFlags, point);
}


void CAjust1Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	bBD = FALSE;

	CDialogEx::OnLButtonUp(nFlags, point);
}


void CAjust1Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (bBD)
	{
		m_pViewController->MainToZoom(point);
	}
	
	CDialogEx::OnMouseMove(nFlags, point);
}


void CAjust1Dlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	m_bBtnDn = true;

	CDialogEx::OnNcLButtonDown(nHitTest, point);
}


void CAjust1Dlg::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	m_bBtnDn = false;

	CDialogEx::OnNcLButtonUp(nHitTest, point);
}


void CAjust1Dlg::OnMoving(UINT fwSide, LPRECT pRect)
{
	CDialogEx::OnMoving(fwSide, pRect);

	if (m_bBtnDn)
	{
		m_pViewController->ResetWindowsPos();
	}

	// TODO: 在此处添加消息处理程序代码
}


void CAjust1Dlg::OnLinear0a()
{
	m_pViewController->iPercent = 0;
	m_pViewController->LinearStretch(0);
	m_pViewController->DrawBaseImage();
}


void CAjust1Dlg::OnLinear2a()
{
	m_pViewController->iPercent = 2;
	m_pViewController->LinearStretch(2);
	m_pViewController->DrawBaseImage();
}


void CAjust1Dlg::OnLinear5a()
{
	m_pViewController->iPercent = 5;
	m_pViewController->LinearStretch(5);
	m_pViewController->DrawBaseImage();
}


void CAjust1Dlg::OnLinear10a()
{
	m_pViewController->iPercent = 10;
	m_pViewController->LinearStretch(10);
	m_pViewController->DrawBaseImage();
}


void CAjust1Dlg::OnRButtonUp(UINT nFlags, CPoint point)
{
	CMenu menu; //定义下面要用到的cmenu对象
	menu.LoadMenu(IDR_MENU5); //装载自定义的右键菜单 
	CMenu *pPopup = menu.GetSubMenu(0); //获取第一个弹出菜单，所以第一个菜单必须有子菜单

	CPoint point1;//定义一个用于确定光标位置的位置 
	GetCursorPos(&point1);//获取当前光标的位置，以便使得菜单可以跟随光标 

	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point1.x, point1.y, this);//在指定位置显示弹出菜单

	CDialogEx::OnRButtonUp(nFlags, point);
}
